/*
 * Инкапсулирует все дом-операции класса CommentSubmit
 * 
 * @author Alexander Sibiryakov, 23.05.08
 */
function CommentSubmitView() {
	this.parent_elt = null;
	this.setParentElt = function(elt) {		this.parent_elt = elt;	}
	this.insertSubmitterHtml = function(html) { 	jQuery( this.parent_elt ).append( html ); }
	this.getParentOid = function() { return jQuery( this.parent_elt ).attr("id"); }
	
	this.getTextAreaElt = function() { return jQuery(this.parent_elt).find("textarea.js_comment-content"); }
	this.getTextAreaId = function() { return jQuery(this.getTextAreaElt()).attr("id"); }
	this.getSubmitBtn = function() { return jQuery(this.parent_elt).find("input.js_submitbutton"); }
	this.getFormElt = function() { return jQuery(this.parent_elt).find(" form.js_submitform"); }
	this.turnOnTinyMCE = function() { 
		/* // возможно его надо включать вот так
			window.tiny_tmp = this;
			var tinyinit = function() {
				if (tiny_tmp.cbody_id) tinyMCE.execCommand('mceAddControl', false, tiny_tmp.cbody_id);
			}.sleep(1);
		*/
		
		tinyMCE.execCommand('mceAddControl', false, this.getTextAreaId()); 
	}
	
	this.getCommentText = function() {
		var cbody_id = this.getTextAreaId();
		if (tinyMCE.getInstanceById(cbody_id)) { 
			var ctext = tinyMCE.getInstanceById(cbody_id).getHTML();
		} else {
			var ctext = jQuery(this.getTextAreaElt()).val();
		}
		return ctext;
	}
	this.cleanTinyMce = function() {
		tinyMCE.getInstanceById(this.getTextAreaId()).setHTML(""); // очистить поле tinymce
	}
	
	this.turnOffTinyMce = function() {
		tinyMCE.execCommand('mceRemoveControl', false, this.getTextAreaId());
	}
	
	this.removeSubmitForm = function() {	jQuery(this.getFormElt()).remove(); }
	this.temp_container = null;
	this.createTemporaryContainer = function() { 
		var tempid = "temp"+this.getParentOid();
		jQuery(this.getFormElt()).before("<div class=\"clist-\" id=\""+tempid+"\"></div>");
		this.temp_container = jQuery("#"+tempid);
	}
	
	this.addToTemporaryContainer = function(html) { jQuery(this.temp_container).append(html);	}
	this.removeTemporaryContainer = function() { jQuery(this.temp_container).remove(); }
	
}